package com.vincent.exam.linkedList;


/**
 * 判断链表是否有环
 * 核心思想是利用快慢指针进行便利
 * 如果链表有环，快慢指针一定会相遇
 */
public class IsLink {

    public boolean isHasLink(ListNode listNode){
        ListNode fast = listNode;
        ListNode slow = listNode;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if (fast == slow) {
                return true;
            }
        }
        return  false;
    }
}
